{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "00,80,00,00,00,00,00,0E,88,1E,BE,DF,C9,E2,FA,00,00,00,00,00,00,00,0A,26,BB,FE,BA,E8,D9,54,00,00,00,00,00,00,00,06,2F,7F,6D,F9,EF,DF,57,00,00,00,04,00,00,00,01,0A,7E,EF,EB,B5,A8,DD,00,00,00,00,00,00,00,08,6A,BD,EE,9C,B1,B3,E5,00,00,00,00,00,00,00,00,72,FB,BE,AF,F9,1E,93,00,00,00,00,00,00,00,00,33,EF,DD,3B,E9,F6,ED,00,00,00,00,00,00,00,04,63,BA,FD,FB,92,A0,F8,00,00,00,00,00,00,00,00,27,F5,DD,7E,9F,66,B1,00,00,00,00,00,00,00,01,FA,F7,FF,BE,F9,6F,3B,00,00,00,00,00,10,00,01,EF,FF,E6,31,DF,FB,35,00,00,00,00,00,00,00,00,A9,E2,D7,8D,63,7B,FD,00,00,00,00,20,00,00,02,9D,BF,F2,F9,F0,A1,9B,00,00,00,00,00,00,00,03,D4,BE,F7,EE,A7,EC,7A,00,00,00,00,10,00,00,00,DF,9D,75,E7,F5,AF,B2,00,00,00,00,00,00,00,00,1C,77,7F,1E,B0,BE,8C,00,00,00,00,70,00,00,00,A6,FC,EF,FF,96,DF,D7,00,00,00,00,00,00,00,01,E7,74,1B,4D,DD,5E,91,00,00,00,00,00,00,00,03,AD,7F,F7,6D,5C,EF,37,00,00,20,00,00,00,00,00,27,77,F5,F9,A7,DF,9B,00,03,30,00,00,00,00,05,06,7E,FF,FC,A9,02,FA,00,00,00,00,00,00,00,01,6F,7E,F7,3F,32,CE,3F,00,00,00,00,00,00,00,07,BA,FC,FE,FD,EC,6C,CF,00,00,00,00,00,00,00,07,77,EF,F9,7F,F8,C4,E6,00,00,00,00,00,00,00,03,5D,DD,DA,FE,CC,A1,FA,00,00,00,00,00,00,00,02,DD,BC,BB,FF,FC,CE,5D,00,00,00,00,00,00,00,01,EB,9F,4D,C6,3E,69,4E,00,00,00,00,00,00,00,02,F9,F7,FB,97,39,90,8A,00,00,00,00,00,00,00,00,69,CE,D9,CD,13,D7,3B,00,00,00,00,00,00,00,00,E1,DF,FF,B4,7E,88,FF,00,00,00,00,00,00,00,01,29,B7,AF,F7,72,32,57,00,00,00,00,00,00,00,00,BC,06,E9,52,ED,22,F7,00,00,20,00,10,00,00,00,5B,E9,FE,FA,AC,7B,AA,00,00,00,10,03,FF,C0,07,B1,37,2F,C5,7A,1B,FD,00,00,00,C0,00,00,00,04,17,17,66,74,7B,89,CA,00,00,00,0E,03,E0,00,11,81,7A,5B,F2,60,13,AB,00,00,00,0E,70,00,00,06,75,39,D7,E2,FB,FA,CE,00,00,00,04,11,C0,00,18,F5,FF,DE,7D,E1,FD,2D,00,00,00,02,00,01,80,17,79,42,3F,F8,34,FB,7D,00,00,00,28,00,00,00,05,DB,9D,DF,A5,70,BC,FC,00,00,00,08,00,00,00,10,A1,63,EF,FC,4D,87,FD,00,00,00,06,00,00,00,08,AE,09,FF,77,E2,C7,F8,00,00,00,00,00,00,00,09,57,EB,FE,DB,D5,87,FC,00,00,00,00,00,00,00,01,71,FF,FE,E9,43,5F,FB,00,00,00,00,00,00,00,02,16,CD,FC,FF,FD,FF,F3,00,00,00,00,00,00,00,0C,1C,7F,FC,EA,F3,9F,F3,00,00,00,00,00,00,00,10,56,AF,FC,FD,DC,7F,C7,00,00,00,00,00,00,00,00,73,DD,FC,3D,19,FF,34,00,00,00,00,00,00,00,01,9D,4B,FC,37,4F,FC,63,00,00,00,00,00,00,00,0C,50,A7,FC,2F,7F,F8,53,00,00,00,00,00,00,00,01,ED,F7,FE,5B,FF,C1,6F,00,00,00,00,00,00,00,00,BC,DD,FE,4B,FF,E2,DF,00,00,00,00,00,00,20,11,7D,67,FF,FF,FF,81,FF,00,00,00,00,00,00,80,0F,FF,FF,FF,FF,FE,01,FF,00,00,00,00,00,03,00,0D,FF,BF,3F,FF,E0,03,FF,00,00,00,00,00,1F,C0,4F,FF,FF,1F,BF,F8,0F,FF,00,00,00,00,01,FF,80,01,1F,FF,9F,BF,F8,1F,FF,00,00,00,00,7F,FF,C0,0C,BF,F7,FF,DF,FC,3F,FC,00,00,00,7F,FF,FF,C0,1C,DF,FF,FF,FF,FE,7F,FC,00,00,3F,FF,FF,FF,00,0C,4F,FF,FF,FF,FF,FF,FE,00,0F,FF,FF,FF,F0,80,00,EF,FF,EF,FF,FF,FF,F1,04,3F,FF,FF,FC,00,00,10,67,E7,C7,FF,FF,FF,A1,02,1F,FF,FF,80,00,00,52,E7,AF,C7,FF,FF,FF,DE,02,1F,FF,E0,00,00,00,71,FF,C3,DF,FF,FF,FE,C9,02,1F,F0,00,00,00,00,29,97,CD,FF,FF,FF,FC,5F,02,1E,00,00,00,00,00,37,3B,BF,FF,FF,FF,F9,FB,00,00,00,00,00,00,10,31,FB,FF,FF,FF,FF,F9,14,00,00,00,00,00,00,01,16,B7,EF,FF,FF,FF,F6,97,04,00,00,00,00,00,18,42,9B,EF,FF,FF,FF,D7,3E,04,00,00,00,00,00,18,DE,B7,FF,FF,FF,FF,EC,2E,04,00,00,00,00,00,1B,47,8F,DF,FF,FF,FF,14,40,04,00,00,00,00,00,18,C2,ED,5F,FF,FF,FF,45,DD,04,00,00,00,00,00,1C,5B,9F,BF,FF,FF,8F,02,05,00,00,00,00,00,00,1C,3C,BC,BF,FF,FF,BC,5E,73,00,00,00,00,00,00,1C,1F,55,FF,FF,FF,F9,DB,F3,20,00,00,00,00,00,1C,15,DA,FE,FF,FF,EA,78,F7,00,00,00,80,00,00,1E,3B,D7,DF,7F,FF,F9,F9,B3,00,00,00,00,00,00,18,EC,D0,F9,7F,FF,E7,BD,D5,00,10,00,00,00,00,1E,DB,F6,D9,BF,D8,6C,FF,97,00,00,00,00,00,00,1E,97,DD,8F,35,FC,FF,BF,58,00,00,00,00,00,00,1F,FC,55,FC,3D,F6,A5,FF,6E,00,00,00,00,00,00,3F,BE,33,3F,26,35,F6,8D,CB,00,00,00,00,00,00,0F,1F,5F,EA,7D,7A,A6,F2,CC,00,00,00,00,00,00,1F,9D,FF,DB,F5,5E,E7,FB,7D,00,00,00,00,00,00,2F,BB,EE,DC,6C,FC,3F,D7,EC,00,00,18,00,00,00,0F,BF,EB,FF,FC,FF,9D,DC,AC,80,00,00,00,00,00,2F,3F,E9,FF,7F,5F,7F,F4,A8,00,00,00,00,00,00,0F,BD,E9,5D,3E,7F,FB,EF,8A,00,40,00,00,00,00,3E,BF,FF,D7,7F,7D,79,FB,13,FC,00,00,00,40,00,1E,FD,FD,FF,FC,FC,DF,7E,29,E8,00,00,00,00,00,3F,FD,EE,F6,FE,F5,1F,BF,E4,08,00,00,00,00,00,1E,FB,FF,FE,DD,57,CD,FF,78,80,80,00,00,00,00,1F,FF,FD,7C,79,47,7E,6F,F6,DC,00,00,00,00,00,3F,FF,F9,FE,FD,D3,F3,FB,BE,00,00,00,00,00,00,1F,DF,FA,FE,A7,AB,8B,8F,7D,1F,80,00,00,00,00,3F,EF,DA,FF,D7,FC,F9,EF,F2,BE,FC,00,00,00,00,3F,FB,EB,D9,5B,CB,FD,9F,CF,FA,00,00,00,00,00,3F,DF,AF,E9,FF,9F,DA,9B,52,F6,00,00,00,00,00,3F,FD,FF,B5,EC,AF,7F,BF,D5,FE,00,00,00,00,00,3F,7F,FE,5D,FD,CF,EF,BF,F9,FF,C8,00,00,00,00,3F,FF,FF,7D,F5,66,FF,BF,F8,FB,80,00,00,00,00,3F,EF,EF,B1,F7,BF,BB,FF,EE,F8,80,00,00,00,00,5F,FF,EF,76,E5,DF,DF,FF,4A,C0,00,04,00,00,00,1F,FF,FE,F6,ED,BF,7C,ED,69,80,60,00,00,00,00,1F,EF,FF,FE,EE,FE,8F,6F,FF,00,00,00,00,00,00,1F,FF,FD,FB,FB,6F,F3,6D,FD,20,00,08,00,00,00,1F,FF,FF,FD,AE,DF,FF,FF,DF,03,FC,C0,00,00,00,5F,FF,DF,7F,FC,DF,FE,F3,F5,FF,FF,00,00,00,00,1F,FF,FF,7D,9E,EF,FF,FE,F7,FF,FF,00,00,00,00,1F,FF,FF,FD,EF,BE,FF,DE,79,FF,E0,00,00,00,00,1F,FF,ED,FF,FF,36,FF,EA,F8,FF,E0,00,0C,00,00,1F,FD,DF,FF,E4,AE,FD,FB,F8,FF,84,00,00,00,00,1F,FF,BF,FB,BF,B7,FB,FB,FF,FF,C0,00,00,00,00,1F,FF,FF,7E,FD,AF,FF,EF,7D,FF,60,00,00,00,00,1F,EF,FF,F9,EE,FF,FF,FF,F1,FF,A0,00,00,00,00,1F,FF,FF,BF,B1,73,FF,F7,FF,FF,F6,00,00,00,00,1F,FE,ED,3B,FA,7B,EF,FE,F9,FF,F0,00,00,00,00,1F,FF,F5,FD,BB,FD,D7,7F,CE,FE,10,00,00,00,00,1F,BF,FF,F6,F7,37,D7,FF,72,FF,DC,00,00,00,00,1F,DF,7F,FA,FD,E6,FE,EF,FF,\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import cv2\n",
    "import numpy as np\n",
    "\n",
    "files_before = []\n",
    "for root, dirs, files in os.walk('.'):\n",
    "    for name in files:\n",
    "        if name[-3:] in ['bmp','png','jpg'] or name[-4:] in ['jpeg']:\n",
    "            files_before.append(os.path.join(root, name))\n",
    "if len(files_before)!=1:\n",
    "    print(\"请重新上传照片，并再次运行程序\")\n",
    "else:\n",
    "    img = cv2.imread(files_before[0],cv2.IMREAD_GRAYSCALE)\n",
    "    img = cv2.resize(img, (120, 120))\n",
    "    res = np.zeros(shape=(120,120))\n",
    "    lens = img.shape[0]*img.shape[1]\n",
    "    for i in range(img.shape[0]):\n",
    "        for j in range(img.shape[1]):\n",
    "            tmp = int(img[i,j]/255+0.5)\n",
    "            res[j,i] = round(tmp,1)\n",
    "    res = res.reshape(-1)\n",
    "    i=0\n",
    "    itr =0\n",
    "    encoder_img = ''\n",
    "    while i < lens:\n",
    "        tmp_str = ''\n",
    "        for j in range(8):\n",
    "            tmp_str += str(res[i+j])[:1]\n",
    "        hex_str = hex(int(tmp_str,2))\n",
    "        hex_str = hex(int(tmp_str,2)).swapcase()\n",
    "        if len(hex_str)<4:\n",
    "            hex_str=hex_str[:2]+'0'+hex_str[-1]\n",
    "        encoder_img += hex_str[-2:]\n",
    "        encoder_img += ','\n",
    "        i += 8\n",
    "        itr+=1\n",
    "\n",
    "    print(encoder_img)\n",
    "    \n",
    "files_before = set()\n",
    "for root, dirs, files in os.walk('.'):\n",
    "    for name in files:\n",
    "        if name[-3:] in ['bmp','png','jpg'] or name[-4:] in ['jpeg']:\n",
    "            os.remove(os.path.join(root, name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
